package top.mccat.common.core.controller.bk;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.mccat.common.annotation.Log;
import top.mccat.common.core.controller.BaseController;
import top.mccat.common.core.domain.AjaxResult;
import top.mccat.common.core.domain.bk.BkSupplier;
import top.mccat.common.core.domain.entity.SysDept;
import top.mccat.common.enums.BusinessType;
import top.mccat.common.service.IBkSupplierService;
import top.mccat.common.utils.poi.ExcelUtil;
import top.mccat.common.core.page.TableDataInfo;

/**
 * 【供应商管理】Controller
 * 
 * @author ruoyi
 * @date 2022-11-06
 */
@RestController
@RequestMapping("/bk/supplier")
public class BkSupplierController extends BaseController
{
    @Autowired
    private IBkSupplierService bkSupplierService;

    /**
     * 查询【供应商管理】列表
     */
    @PreAuthorize("@ss.hasPermi('bk:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(BkSupplier bkSupplier)
    {
        startPage();
        List<BkSupplier> list = bkSupplierService.selectBkSupplierList(bkSupplier);
        return getDataTable(list);
    }

    /**
     * 获取部门下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(BkSupplier bkSupplier)
    {
        List<BkSupplier> list = bkSupplierService.selectBkSupplierList(bkSupplier);
        return AjaxResult.success(bkSupplierService.buildSupplierTreeSelect(list));
    }

    /**
     * 导出【供应商管理】列表
     */
    @PreAuthorize("@ss.hasPermi('bk:supplier:export')")
    @Log(title = "【供应商管理】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BkSupplier bkSupplier)
    {
        List<BkSupplier> list = bkSupplierService.selectBkSupplierList(bkSupplier);
        ExcelUtil<BkSupplier> util = new ExcelUtil<BkSupplier>(BkSupplier.class);
        util.exportExcel(response, list, "【供应商管理】数据");
    }

    /**
     * 获取【供应商管理】详细信息
     */
    @PreAuthorize("@ss.hasPermi('bk:supplier:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(bkSupplierService.selectBkSupplierById(id));
    }

    /**
     * 新增【供应商管理】
     */
    @PreAuthorize("@ss.hasPermi('bk:supplier:add')")
    @Log(title = "【供应商管理】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BkSupplier bkSupplier)
    {
        return toAjax(bkSupplierService.insertBkSupplier(bkSupplier));
    }

    /**
     * 修改【供应商管理】
     */
    @PreAuthorize("@ss.hasPermi('bk:supplier:edit')")
    @Log(title = "【供应商管理】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BkSupplier bkSupplier)
    {
        return toAjax(bkSupplierService.updateBkSupplier(bkSupplier));
    }

    /**
     * 删除【供应商管理】
     */
    @PreAuthorize("@ss.hasPermi('bk:supplier:remove')")
    @Log(title = "【供应商管理】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(bkSupplierService.deleteBkSupplierByIds(ids));
    }
}
